package VISTA.ventanas;

import javax.swing.ImageIcon;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

public class mdiPrincipal extends javax.swing.JFrame {

    /**
     * Creates new form mdiPrincipal
     */
    public mdiPrincipal() {
        initComponents();
        //Maximiso el MDI para que ocupe todo el ancho y alto de la pantalla
        this.setExtendedState(MAXIMIZED_BOTH);
        //Cambio el titulo que tendra el mdi
        this.setTitle("Ritza");
        //Cambio el icono de la ventata por uno que hemos crado
        ImageIcon icono = new ImageIcon(getClass().getResource("/VISTA/iconos/general/ritza icon.png"));
        this.setIconImage(icono.getImage());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktop = new JCDesktopPane.JCDesktopPane();
        jmbMuenus = new javax.swing.JMenuBar();
        jmArchivo = new javax.swing.JMenu();
        jmiSalir = new javax.swing.JMenuItem();
        jmPagos = new javax.swing.JMenu();
        jmiPagoCliente = new javax.swing.JMenuItem();
        jmiPagoProveedores = new javax.swing.JMenuItem();
        jmiPagoEmpleados = new javax.swing.JMenuItem();
        jmCatalogos = new javax.swing.JMenu();
        jmiListaPAgos = new javax.swing.JMenuItem();
        jmiProduccion = new javax.swing.JMenuItem();
        jmAcercaDe = new javax.swing.JMenu();
        jmiPrograma = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1024, 600));

        desktop.setImagenDeFondo(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/ritza fondo.png"))); // NOI18N
        desktop.setPreferredSize(new java.awt.Dimension(1024, 600));

        jmbMuenus.setBackground(new java.awt.Color(102, 51, 0));

        jmArchivo.setBackground(new java.awt.Color(255, 255, 255));
        jmArchivo.setMnemonic('f');
        jmArchivo.setText("Archivo");

        jmiSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/Cancel.png"))); // NOI18N
        jmiSalir.setText("Cerrar Programa");
        jmiSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiSalirActionPerformed(evt);
            }
        });
        jmArchivo.add(jmiSalir);

        jmbMuenus.add(jmArchivo);

        jmPagos.setBackground(new java.awt.Color(255, 255, 255));
        jmPagos.setMnemonic('e');
        jmPagos.setText("Pagos");

        jmiPagoCliente.setMnemonic('C');
        jmiPagoCliente.setText("Clientes");
        jmiPagoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiPagoClienteActionPerformed(evt);
            }
        });
        jmPagos.add(jmiPagoCliente);

        jmiPagoProveedores.setMnemonic('P');
        jmiPagoProveedores.setText("Proveedores");
        jmiPagoProveedores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiPagoProveedoresActionPerformed(evt);
            }
        });
        jmPagos.add(jmiPagoProveedores);

        jmiPagoEmpleados.setMnemonic('E');
        jmiPagoEmpleados.setText("Empleados");
        jmiPagoEmpleados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiPagoEmpleadosActionPerformed(evt);
            }
        });
        jmPagos.add(jmiPagoEmpleados);

        jmbMuenus.add(jmPagos);

        jmCatalogos.setBackground(new java.awt.Color(255, 255, 255));
        jmCatalogos.setText("Catálogos");

        jmiListaPAgos.setMnemonic('L');
        jmiListaPAgos.setText("Lista de pagos");
        jmiListaPAgos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiListaPAgosActionPerformed(evt);
            }
        });
        jmCatalogos.add(jmiListaPAgos);

        jmiProduccion.setMnemonic('P');
        jmiProduccion.setText("Producción");
        jmiProduccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiProduccionActionPerformed(evt);
            }
        });
        jmCatalogos.add(jmiProduccion);

        jmbMuenus.add(jmCatalogos);

        jmAcercaDe.setBackground(new java.awt.Color(255, 255, 255));
        jmAcercaDe.setMnemonic('h');
        jmAcercaDe.setText("Acerca De...");

        jmiPrograma.setMnemonic('P');
        jmiPrograma.setText("Programa");
        jmiPrograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiProgramaActionPerformed(evt);
            }
        });
        jmAcercaDe.add(jmiPrograma);

        jmbMuenus.add(jmAcercaDe);

        setJMenuBar(jmbMuenus);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jmiSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiSalirActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jmiSalirActionPerformed

    private void jmiPagoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiPagoClienteActionPerformed
        try {
            PagosDeClientes pdc = new PagosDeClientes();
            pdc.setTitle("Pago de Clientes");
            if (exist(pdc) == false) {
                desktop.add(pdc);
                pdc.setVisible(true);
                pdc.setLocation((desktop.getWidth() - pdc.getWidth()) / 2,
                        (desktop.getHeight() - pdc.getHeight()) / 2);
            } else {
                pdc.dispose();
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Ha ocurrido un error: " + e, "Error", 0);
        }        // 
    }//GEN-LAST:event_jmiPagoClienteActionPerformed

    private void jmiPagoProveedoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiPagoProveedoresActionPerformed
        try {
            PagosDeProveedores pdp = new PagosDeProveedores();
            pdp.setTitle("Pago de Proveedores");
            if (exist(pdp) == false) {
                desktop.add(pdp);
                pdp.setVisible(true);
                pdp.setLocation((desktop.getWidth() - pdp.getWidth()) / 2,
                        (desktop.getHeight() - pdp.getHeight()) / 2);
            } else {
                pdp.dispose();
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Ha ocurrido un error: " + e, "Error", 0);
        }
    }//GEN-LAST:event_jmiPagoProveedoresActionPerformed

    private void jmiPagoEmpleadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiPagoEmpleadosActionPerformed
        try {
            PagosDeEmpleados pde = new PagosDeEmpleados();
            pde.setTitle("Pago de Empleados");
            if (exist(pde) == false) {
                desktop.add(pde);
                pde.setVisible(true);
                pde.setLocation((desktop.getWidth() - pde.getWidth()) / 2,
                        (desktop.getHeight() - pde.getHeight()) / 2);
            } else {
                pde.dispose();
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Ha ocurrido un error: " + e, "Error", 0);
        }
    }//GEN-LAST:event_jmiPagoEmpleadosActionPerformed

    private void jmiListaPAgosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiListaPAgosActionPerformed
        try {
            CatalogoDePagos CPD = new CatalogoDePagos();
            CPD.setTitle("Catálogo de pagos");
            if (exist(CPD) == false) {
                desktop.add(CPD);
                CPD.setVisible(true);
                CPD.setLocation((desktop.getWidth() - CPD.getWidth()) / 2,
                        (desktop.getHeight() - CPD.getHeight()) / 2);
            } else {
                CPD.dispose();
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Ha ocurrido un error: " + e, "Error", 0);
        }
    }//GEN-LAST:event_jmiListaPAgosActionPerformed

    private void jmiProduccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiProduccionActionPerformed
        try {
            ControlDeProduccion CDP = new ControlDeProduccion();
            CDP.setTitle("Control de producción");
            if (exist(CDP) == false) {
                desktop.add(CDP);
                CDP.setVisible(true);
                CDP.setLocation((desktop.getWidth() - CDP.getWidth()) / 2,
                        (desktop.getHeight() - CDP.getHeight()) / 2);
            } else {
                CDP.dispose();
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Ha ocurrido un error: " + e, "Error", 0);
        }
    }//GEN-LAST:event_jmiProduccionActionPerformed

    private void jmiProgramaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiProgramaActionPerformed
        AcercaDe ad = new AcercaDe();
        try {
            if (exist(ad) == false) {
                    desktop.add(ad);
                    ad.setVisible(true);
                    ad.setLocation((desktop.getWidth() - ad.getWidth()) / 2,
                            (desktop.getHeight() - ad.getHeight()) / 2);
                } else {
                    ad.dispose();
                }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Ha ocurrido un error: " + ex, "Error", 0);
        }
    }//GEN-LAST:event_jmiProgramaActionPerformed

    public boolean exist(JInternalFrame frame) throws Exception {

        try {
            JInternalFrame iframes[] = desktop.getAllFrames();
            for (int i = 0; i < iframes.length; i++) {
                if (iframes[i].getTitle().equals(frame.getTitle())) {
                    iframes[i].moveToFront();
                    iframes[i].setSelected(true);
                    iframes[i].setLocation((desktop.getWidth() - iframes[i].getWidth()) / 2,
                            (desktop.getHeight() - iframes[i].getHeight()) / 2);
                    return true;
                }
            }
        } catch (Exception e) {
            throw e;
        }
        return false;
    }
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(mdiPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(mdiPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(mdiPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(mdiPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new mdiPrincipal().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static JCDesktopPane.JCDesktopPane desktop;
    private javax.swing.JMenu jmAcercaDe;
    private javax.swing.JMenu jmArchivo;
    private javax.swing.JMenu jmCatalogos;
    private javax.swing.JMenu jmPagos;
    private javax.swing.JMenuBar jmbMuenus;
    private javax.swing.JMenuItem jmiListaPAgos;
    private javax.swing.JMenuItem jmiPagoCliente;
    private javax.swing.JMenuItem jmiPagoEmpleados;
    private javax.swing.JMenuItem jmiPagoProveedores;
    private javax.swing.JMenuItem jmiProduccion;
    private javax.swing.JMenuItem jmiPrograma;
    private javax.swing.JMenuItem jmiSalir;
    // End of variables declaration//GEN-END:variables
}
